﻿using System;
using Microsoft.Xna.Framework.Graphics;
using ShevaEngine.Core.Interfaces;

namespace ShevaEngine.Core.Modules.Graphics
{
    /// <summary>
    /// Draw call.
    /// </summary>
    public class UserPrimitivesDrawCall<T> : DrawCall where T : struct, IVertexType
    {
        /// <summary>Typ primitiva.</summary>
        public PrimitiveType PrimitiveType;
        /// <summary>Vertices;</summary>
        public T[] Vertices;
        /// <summary>The number of primitives to render.</summary>
        public int PrimitiveCount;
        
        /// <summary>
        /// Konstruktor.
        /// </summary>
        public UserPrimitivesDrawCall(PrimitiveType primitiveType, T[] data, Int32 primitiveCount)
            : base()
        {
            this.PrimitiveType = primitiveType;
            this.Vertices = data;
            this.PrimitiveCount = primitiveCount;
        }

        /// <summary>
        /// Metoda vykresli objekt
        /// </summary>
        public override void Render()
        {
            ShevaEngine.Instance.GraphicsDevice.DrawUserPrimitives<T>(this.PrimitiveType, this.Vertices, 0, this.PrimitiveCount);
        }

        /// <summary>
        /// Metoda vykresli objekt
        /// </summary>
        public override void RenderHWInstancing(int instancesCount)
        {
            throw new Exception("Impossible !");
        }

        ///// <summary>
        ///// Method clones object.
        ///// </summary>
        ///// <returns></returns>
        //public object Clone()
        //{
        //    UserPrimitivesDrawCall<T> newDrawCall = new UserPrimitivesDrawCall<T>();

        //    newDrawCall.PrimitiveCount = this.PrimitiveCount;
        //    newDrawCall.PrimitiveType = this.PrimitiveType;
            
        //    newDrawCall.Vertices = new T[this.Vertices.Length];

        //    for (int i = 0; i < this.Vertices.Length; i++)
        //        newDrawCall.Vertices[i] = this.Vertices[i];
        
        //    return newDrawCall;
        //}
    }
}
